<?php  
class Mbanners extends CI_model{ 
     // đếm tổng số record trong table book 
    public function count_all(){ 
        return $this->db->count_all('banner'); 
    }
    public function listall(){
        $this->db->order_by("Banner_id", "desc"); 
		$query=$this->db->get("banner");
        return $query->result_array();
    }

    public function Insert($data) {
        $this->db->insert('banner',$data);
        return $this->db->insert_id();
    }

    public function Delete($id) {
    	$data = $this->GetBanner($id);
    	$this->db->where('Banner_id', $id);
    	$this->db->delete('banner');
    	$pathImage = 'public/frontend/images/banner/'.$data->urlHinh;
    	@unlink($pathImage);
        return $this->db->affected_rows(); 
    }
	 public function GetBannerActive(){
		$this->db->where("Active",1);
		$this->db->order_by("Banner_id", "desc"); 
        $query=$this->db->get("banner");
        return $query->result_array();
    }
     public function GetBanner($id){
        $this->db->where("Banner_id",$id);
        $query=$this->db->get('banner');
        $data = $query->row();
        return $data; 
    }

    public function Update($data, $Banner_id) {
        $this->db->where('Banner_id', $Banner_id);
        $this->db->update('banner', $data); 
    }
}